package org.lql.chaos.common.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.lql.chaos.common.constant.ErrorCode;

/**
 * @author: liangqinglong
 * @date: 2025-07-02 09:51
 * @description:
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ApiResponse<T> {

	private int code;

	private String message;

	private T data;

	private long timestamp = System.currentTimeMillis();

	public static <T> ApiResponse<T> success() {
		return new ApiResponse<>(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMessage(), null, System.currentTimeMillis());
	}

	public static <T> ApiResponse<T> success(T data) {
		return new ApiResponse<>(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMessage(), data, System.currentTimeMillis());
	}

	public static <T> ApiResponse<T> error(ErrorCode errorCode) {
		return new ApiResponse<>(errorCode.getCode(), errorCode.getMessage(), null, System.currentTimeMillis());
	}

}